package com.lucker.common.util;


import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.lucker.common.model.BetMenuObj;
import com.lucker.common.model.BetSingleNumbersObj;
import com.lucker.common.model.BetTargetObj;

/**
 * Created by PC on 2019/6/25.
 */

public class CountTotalBonusUtil {
    //获取号码组合的基础中奖金额
    //betTargetObjs：投注号码列表
    //awardNumbers：开奖号码
    //返回该次投注的基础中奖金额，总中奖金额要乘以倍数
    public static int getTotalBonus(List<BetMenuObj> betMenuListObjs,List<BetTargetObj> betTargetObjs,List<Integer> awardNumbers){
        List<BetSingleNumbersObj> betSingleNumbersObjs = new ArrayList<>();
        for (int i = 0; i < betTargetObjs.size(); i++) {
            BetTargetObj betTargetObj = betTargetObjs.get(i);
            System.out.println(JSONObject.toJSONString(betTargetObjs) + "    =======================================");
            BetMenuObj betMenuObj = BetUtil.turnK12DanToNormal(betMenuListObjs,betTargetObj.getBetMenuObj());
            System.out.println("=============================>  :  " + JSONObject.toJSONString(betMenuObj));
            int numtypeId = Integer.valueOf(betMenuObj.getTypeId());
            int moneys = Integer.valueOf(betMenuObj.getBouns());
            List<List<Integer>> numbers = BetUtil.getSingleNumberList(betTargetObj);
            System.out.println("--------------------------------------------------------------------->  :  " + JSONObject.toJSONString(numbers));
            for (List<Integer> list : numbers) {
                BetSingleNumbersObj betSingleNumbersObj = new BetSingleNumbersObj();
                betSingleNumbersObj.setTypeId(numtypeId);
                betSingleNumbersObj.setNumbers(list);
                betSingleNumbersObj.setMoney(moneys);
                betSingleNumbersObjs.add(betSingleNumbersObj);
            }
            
            System.out.println("==========*************************==================>  :  " + JSONObject.toJSONString(betSingleNumbersObjs));
        }
        int awardMoney = 0;
        for (BetSingleNumbersObj singleNumber : betSingleNumbersObjs) {
            int singleTypeId = singleNumber.getTypeId();
            List<Integer> singleNumbers = singleNumber.getNumbers();
            if (singleTypeId <= 3) {//任二到任五
                if (awardNumbers.containsAll(singleNumbers)) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId <= 6) {//任六到任八
                if (singleNumbers.containsAll(awardNumbers)) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId == 7) {//前一直
                if (awardNumbers.get(0) == singleNumbers.get(0)) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId == 8) {//前二直选
                if (awardNumbers.get(0) == singleNumbers.get(0) && awardNumbers.get(1) == singleNumbers.get(1)) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId == 9) {//前二组选
                if (singleNumbers.contains(awardNumbers.get(0)) && singleNumbers.contains(awardNumbers.get(1))) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId == 10) {//前三直选
                if (awardNumbers.get(0) == singleNumbers.get(0) && awardNumbers.get(1) == singleNumbers.get(1) && awardNumbers.get(2) == singleNumbers.get(2)) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            } else if (singleTypeId == 11) {//前三组选
                if (singleNumbers.contains(awardNumbers.get(0)) && singleNumbers.contains(awardNumbers.get(1)) && singleNumbers.contains(awardNumbers.get(2))) {
                    awardMoney = awardMoney + singleNumber.getMoney();
                }
            }
        }
        return awardMoney;
    }
}
